package com.hanhanxiaochong.zhongxiangchuanmei.view.home.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.NearByShopBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.CommonAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ViewHolder;
import com.hanhanxiaochong.zhongxiangchuanmei.util.ResourcesUtils;
import com.hanhanxiaochong.zhongxiangchuanmei.util.glide.GlideImgManager;
import com.hanhanxiaochong.zhongxiangchuanmei.widget.StarBar;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.text.DecimalFormat;
import java.util.List;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/4/23.
 * Desc   :
 */

public class NearbyShopAdapter extends CommonAdapter<NearByShopBean> {

    public NearbyShopAdapter(Context context, int layoutId, List<NearByShopBean> list) {
        super(context, layoutId, list);
    }

    @Override
    protected void convert(ViewHolder holder, NearByShopBean bean, final int position) {
        TextView shopName = holder.getView(R.id.tv_shop_name);
        StarBar shopStar = holder.getView(R.id.shop_star);
        TextView shopScore = holder.getView(R.id.tv_shop_score);
        TextView shopEvaluation = holder.getView(R.id.tv_shop_evaluation);
        TextView shopDistance = holder.getView(R.id.tv_shop_distance);
        TextView shopAddress = holder.getView(R.id.tv_shop_address);
        ImageView shopLogo = holder.getView(R.id.iv_shop_logo);
        shopName.setText(bean.getName());
        shopStar.setClickable(false);
        shopStar.setStarMark(Float.parseFloat(bean.getScore()));
        shopScore.setText(String.format(ResourcesUtils.getString(R.string.good_score), bean.getScore()));
        shopEvaluation.setText(String.format(ResourcesUtils.getString(R.string.good_evaluation), bean.getStarNum()));
        shopDistance.setText(String.format(ResourcesUtils.getString(R.string.shop_distance),
                new DecimalFormat("0.00").format(Double.parseDouble(bean.getMQ_DISTANCE()))));
        shopAddress.setText(bean.getProvince() + bean.getCity() + bean.getArea() + bean.getAddresser());
        GlideImgManager.glideLoader(mContext, RetrofitSource.image_url + bean.getPic().split(",")[0], R.mipmap.img_error, R.mipmap.img_error, shopLogo, 0);
        holder.setOnClickListener(R.id.item_nearby_shop, v -> mOnItemClickListener.onItemClick(NearbyShopAdapter.this, position));
    }

}
